#coding=utf-8

class getpostRouter(object):
	'''保证 ImgFile ImgUrl 两个表只在数据库 db_postpic 中创建
  '''
	def db_for_read(self, model, **hints):
##		print('db_for_read: %s'%(model._meta.object_name,))
		if model._meta.object_name	in ('ImgFile','ImgUrl'):
			return 'db_postpic'
		return None

	def db_for_write(self, model, **hints):
		if model._meta.object_name	in ('ImgFile','ImgUrl'):
			return 'db_postpic'
		return None

	def allow_relation(self, obj1, obj2, **hints):
##		print('allow_relation: %s and %s'%(obj1._meta.object_name,obj2._meta.object_name))
		if obj1._meta.object_name in  ('ImgFile','ImgUrl') or obj2._meta.object_name in ('ImgFile','ImgUrl'):
			return obj1._meta.object_name in  ('ImgFile','ImgUrl') and obj2._meta.object_name in ('ImgFile','ImgUrl')

		return None

	def allow_syncdb(self, db, model):
##		print('%s -- %s'%(db,model._meta.object_name))
		if db == 'db_postpic':
			return model._meta.object_name in  ('ImgFile','ImgUrl')
		elif model._meta.object_name in  ('ImgFile','ImgUrl') :
			return False

		return None

